import java.util.*;

/**
 * 卡牌分组
 *
 * @USER: Administrator
 * @DATE: 2024/9/16 下午11:54
 * @VERSION: 1.0.0
 */
public class LC914 {
    public static void main(String[] args) {
        LC914 lc914 = new LC914();
        System.out.println(lc914.hasGroupsSizeX(new int[]{1,1,1,2,2,2,3,3}));
    }
    public boolean hasGroupsSizeX(int[] deck) {
        Arrays.sort(deck);
        Map<Integer, Integer> map = new HashMap<>();
        for (int j : deck) {
            map.put(j, map.getOrDefault(j, 0) + 1);
        }

        List<Integer> result = new ArrayList<>();
        int min = Integer.MAX_VALUE;
        for (Integer i : map.keySet()) {
            if (min<map.get(i)) {
                min=map.get(i);
            }
            result.add(map.get(i));
        }

        int common = result.get(0);
        for (int i = 1; i < result.size(); i++) {
            common = getMaxCommonDivisor(Math.min(common,result.get(i)),Math.max(common,result.get(i)));
        }

        return common>=2;
    }

    public int getMaxCommonDivisor(int min,int max) {
        return max%min==0?min:getMaxCommonDivisor(max%min,min);
    }

}
